/*
 * Created on 13/08/2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package br.com.site.model.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


import br.com.site.model.dao.DAOException;
import br.com.site.model.dao.DAOFactory;
import br.com.site.model.dao.EventoDAO;

/**
 * @author pgr-eduardo
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
@Entity
public class Evento implements CrudBaseEntity<Evento, Long>, Auditoria{
	
	
	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	private Long id;
	
	@ManyToOne(fetch=FetchType.LAZY, targetEntity=br.com.site.model.entity.Estande.class)	
    @JoinColumn(name="estande")
	private Estande estandeMural;
	
	@Column(columnDefinition="text")
	private String texto;
	
	
	@Temporal(value=TemporalType.DATE)
	private Date exporAte;
	
	/*Auditoria*/  
	  @Column(name = "loginUsuario", nullable = false)
	  private String loginUsuario;
	  
	  @Column(name = "dtCriacao", nullable = false)
	  private Date dtCriacao;
	  
	  @Column(name = "dtModificacao", nullable = false)
	  private Date dtModificacao;
	  
	  @Column(name = "ativo", nullable = false)
	  private boolean ativo;
	
	
	/**
	 * @return Returns the curso.
	 */
	
	/**
	 * @return Returns the texto.
	 */
	public String getTexto() {
		return texto;
	}
	/**
	 * @param texto The texto to set.
	 */
	public void setTexto(String texto) {
		this.texto = texto;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public Estande getEstandeMural() {
		return estandeMural;
	}
	public void setEstandeMural(Estande estandeMural) {
		this.estandeMural = estandeMural;
	}
	public String getLoginUsuario() {
		return loginUsuario;
	}
	public void setLoginUsuario(String loginUsuario) {
		this.loginUsuario = loginUsuario;
	}
	public Date getDtCriacao() {
		return dtCriacao;
	}
	public void setDtCriacao(Date dtCriacao) {
		this.dtCriacao = dtCriacao;
	}
	public Date getDtModificacao() {
		return dtModificacao;
	}
	public void setDtModificacao(Date dtModificacao) {
		this.dtModificacao = dtModificacao;
	}
	public boolean isAtivo() {
		return ativo;
	}
	public void setAtivo(boolean ativo) {
		this.ativo = ativo;
	}
	
	
	public Date getExporAte() {
		return exporAte;
	}
	public void setExporAte(Date exporAte) {
		this.exporAte = exporAte;
	}
	@Override
	public void remove() throws BusinessException {
		DAOFactory factory = DAOFactory.getInstance();
		try{
			factory.txBegin();
			EventoDAO dao = factory.getDao(EventoDAO.class);			
			dao.remove(this.id);

			factory.txCommit();
		}catch (DAOException e){
			factory.txRollback();
			throw new BusinessException(e);
		}finally{
			factory.shutdown();
		}
		
	}
	@Override
	public void save() throws BusinessException {
		
		DAOFactory factory = DAOFactory.getInstance();
		try{
			factory.txBegin();
			EventoDAO dao = factory.getDao(EventoDAO.class);			
			dao.save(this);

			factory.txCommit();
		}catch (DAOException e){
			factory.txRollback();
			throw new BusinessException(e);
		}finally{
			factory.shutdown();
		}
	}
	
	
	
	public static Evento find(Long oid){
		DAOFactory factory = DAOFactory.getInstance();
		EventoDAO dao = factory.getDao(EventoDAO.class);
		
		return dao.find(oid);
	}
	public static List<Evento> find(){
		DAOFactory factory = DAOFactory.getInstance();
		EventoDAO dao = factory.getDao(EventoDAO.class);

		return dao.find();
	}
	
	public static List<Evento> findByCriteria(Evento avisoMural){
		DAOFactory factory = DAOFactory.getInstance();
		EventoDAO dao = factory.getDao(EventoDAO.class);

		return dao.findByCriteria(avisoMural);
	}
	
	public static List<Evento> find(int first, int max){
		DAOFactory factory = DAOFactory.getInstance();
		EventoDAO dao = factory.getDao(EventoDAO.class);

		return dao.find(first, max);
	}
	
	public static List<Evento> findByCriteria(Evento avisoMural, int first, int max)
	{
		DAOFactory factory = DAOFactory.getInstance();
		EventoDAO dao = factory.getDao(EventoDAO.class);

		return dao.findByCriteria(avisoMural, first, max);
		
	}
 
	
	
}
